package com.nexus.all.manager;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nexus.all.dao.NoteMapper;
import com.nexus.all.dto.NoteQueryDTO;
import com.nexus.all.model.Note;
import com.nexus.bean.utils.CollectionsUtil;
import com.nexus.bean.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class NoteManager extends ServiceImpl<NoteMapper, Note> {

    public Page<Note> queryNotes(NoteQueryDTO dto) {
        Page<Note> page = new Page<>();
        page.setCurrent(dto.getPageNo());
        page.setSize(dto.getPageSize());
        LambdaQueryWrapper<Note> queryWrapper = Note.gw();
        if (CollectionsUtil.isNotEmpty(dto.getNoteIds())) {
            queryWrapper.in(Note::getId, dto.getNoteIds());
        }
        if (StringUtils.isNotBlank(dto.getKeyword())) {
            queryWrapper.like(Note::getTitle, dto.getKeyword());
        }
        queryWrapper.orderByDesc(Note::getCreateTime);
        return page(page, queryWrapper);
    }
}
